@@ -69,20 +69,20 @@ end |
||
| 69 | 69 |
|
| 70 | 70 |
require 'mini_magick' |
| 71 | 71 |
|
| 72 |
-def convert_image(source, target, width: nil, round: false) |
|
| 72 |
+def convert_image(source, target, options = {}) # width: nil, round: false
|
|
| 73 | 73 |
ext = target[/(?<=\.)[^.]+\z/] || 'png' |
| 74 | 74 |
original = MiniMagick::Image.open(source) |
| 75 | 75 |
|
| 76 | 76 |
result = original |
| 77 | 77 |
result.format ext |
| 78 | 78 |
|
| 79 |
- if width |
|
| 79 |
+ if width = options[:width] |
|
| 80 | 80 |
result.thumbnail '%1$dx%1$d>' % width |
| 81 | 81 |
else |
| 82 | 82 |
width = result[:width] |
| 83 | 83 |
end |
| 84 | 84 |
|
| 85 |
- if round |
|
| 85 |
+ if options[:round] |
|
| 86 | 86 |
radius = (Rational(80, 512) * width).round |
| 87 | 87 |
|
| 88 | 88 |
mask = MiniMagick::Image.create(ext) { |tmp| result.write(tmp) }
|